home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / beginners / tutorial / deepend / 2 - complex example commented.bb < prev    next >
Encoding:
Text File  |  2002-04-10  |  2.7 KB  |  84 lines

  1.  
  2. ; ---------------------------------------------------------------------
  3. ; Complex example of double-buffered animation - support@blitzbasic.com
  4. ; ---------------------------------------------------------------------
  5.  
  6. ; Not complex at all, just complex compared to the simple example.
  7. ; (Refer to that example for more detailed explanations of the basics
  8. ; used here.)
  9.  
  10. ; To see this code without all the comments, see "complex example
  11. ; uncommented.bb"...
  12.  
  13. ; USE THE CURSOR KEYS TO CONTROL THE ROCKET!
  14.  
  15. ; ---------------------------------------------------------------------
  16. ; Open a 640 x 480 display...
  17. ; ---------------------------------------------------------------------
  18.  
  19. Graphics 640, 480
  20.  
  21. ; ---------------------------------------------------------------------
  22. ; Set up double-buffered animation
  23. ; ---------------------------------------------------------------------
  24.  
  25. SetBuffer BackBuffer ()
  26.  
  27. ; ---------------------------------------------------------------------
  28. ; Load images and set transparent mask where appropriate...
  29. ; ---------------------------------------------------------------------
  30.  
  31. background = LoadImage ("george.bmp")
  32.  
  33. player = LoadImage ("rocket.bmp")
  34. MaskImage player, 255, 0, 255
  35.  
  36. foreground = LoadImage ("xmas.bmp")
  37. MaskImage foreground, 255, 0, 255
  38.  
  39. ; ---------------------------------------------------------------------
  40. ; Set player's start position...
  41. ; ---------------------------------------------------------------------
  42.  
  43. ; We're using two 'variables' called x and y to store the player's
  44. ; position on screen. When we check for keypresses, we'll increase
  45. ; and decrease these values to change the player's position...
  46.  
  47. x = 320
  48. y = 340
  49.  
  50. ; ---------------------------------------------------------------------
  51. ; Main game loop
  52. ; ---------------------------------------------------------------------
  53.  
  54. Repeat
  55.  
  56.     Cls
  57.     
  58.     ; -----------------------------------------------------------------
  59.     ; Check keypresses...
  60.     ; -----------------------------------------------------------------
  61.  
  62.     ; Here, we increase and decrease x and y when the cursors are
  63.     ; pressed, then we draw the rocket at that x/y position... the key
  64.     ; codes used are listed in the Help section. Try changing them to use
  65.     ; different keys...
  66.     
  67.     If KeyDown (203) Then x = x - 1 ; Left cursor
  68.     If KeyDown (205) Then x = x + 1 ; Right cursor
  69.     If KeyDown (200) Then y = y - 1 ; Up cursor
  70.     If KeyDown (208) Then y = y + 1 ; Down cursor
  71.  
  72.     ; -----------------------------------------------------------------
  73.     ; Draw images in order, from furthest away to nearest...
  74.     ; -----------------------------------------------------------------
  75.  
  76.     TileImage background
  77.     DrawImage player, x, y
  78.     DrawImage foreground, 0, 250
  79.     
  80.     Flip
  81.     
  82. Until KeyHit (1)
  83.  
  84. End